package org.hishenframework.core.web.menu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MenuItemBean implements Comparable<MenuItemBean> {

	private String type;
	private int order = Integer.MAX_VALUE;
	private List<MenuSubItemBean> menuSubItemBean = new ArrayList<MenuSubItemBean>();
	
	public MenuItemBean(String type, int order) {
		this.type = type;
		this.order = order;
	}
	
	public void add(MenuSubItemBean subItemBean) {
		menuSubItemBean.add(subItemBean);
		//TODO:可优化
		Collections.sort(menuSubItemBean);
		//将最小的二级菜单序列作为父一级菜单的序列
		if (order > subItemBean.getOrder()) {
			order = subItemBean.getOrder();
		}
	}
	
	public int getOrder() {
		return order;
	}
	public void setOrder(int order) {
		this.order = order;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public List<MenuSubItemBean> getMenuSubItemBean() {
		return menuSubItemBean;
	}
	public void setMenuSubItemBean(List<MenuSubItemBean> menuSubItemBean) {
		this.menuSubItemBean = menuSubItemBean;
	}

	@Override
	public int compareTo(MenuItemBean o) {
		return order > o.order ? 1 : -1;
	}
}
